

import Unit from "../../qbasics/basics/Row";
import module from "../../qbasics/basics/Block";
import Sentence from "../entity/Sentence";
import domain from "../../qbasics/basics/Phere";

export default class Switch{
    constructor(){
        this.sentenc= new Sentence();

    }
    /**
     * 输出树格式
     */
    findTree(){
      return    this.sentenc.findRun(1);
    }

    /**
     * 数组格式
     *
     */
    findArray(){
        return   this. sentenc.findRunData(11);
    }

    /**
     * 输出Phere格式
     */
    findPhere(){
        return this.sentenc;

    }

    run(tree){
      this.sentenc=new  Sentence();
      this.genIntCode(tree)
        this.sentenc;
    }
    genIntCode ( tree)  {
            let  root = tree;
            let  blk1, blk2,cond, jump2else, thenpart, jump2end, elsepart, endif;
            let id1,id2,id3,block;
        switch (root.type)  {
            case 'STMT_LIST':
                blk1 =  this.genIntCode (root.data[0]);
                blk2 =this.genIntCode (root.data[1]);
                 this.sentenc.blockAddRow(blk1,new Row(blk2,"1"));

                return blk1;

            case 'EMPTY_STMT':
                block= new Block();
                id1=this.sentenc.addData(new Row('0'),block);
                return id1;
                break;
            case 'statement_名词A':
            case 'statement_结构A':
            case 'statement_动作A':
                 return this.genIntCode (root.data[0]);
                break;
            case '动词名词':
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                cond = this.genIntCode (root.data[1]);
                block.addRow(new Row( blk1,cond,"2"))
                id1=this.sentenc.addData(new Row('1'),block);
                this.sentenc.blockAddRow(1,new Row(id1))
                return id1;
                break;
            case '把名词动词':
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                cond = this.genIntCode (root.data[1]);
                block.addRow(new Row( blk1,cond,"2"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '把名词动词到名词':
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                cond = this.genIntCode (root.data[1]);
                blk2 = this.genIntCode (root.data[2]);
                block.addRow(new Row( blk1,cond,blk2,"2"))
                id1=this.sentenc.addData(new Row('1'),block);
                this.sentenc.blockAddRow(1,new Row(id1))
                return id1;
                break;
            case '名词A': //
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                block.addRow(new Row( blk1,"0"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '结构A': //
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                block.addRow(new Row( blk1,"0"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '和结构':
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                blk2 = this.genIntCode (root.data[1]);
                block.addRow(new Row( blk1,blk2,"1"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '的名词': //
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                blk2 = this.genIntCode (root.data[1]);
                block.addRow(new Row( blk1,blk2,"0"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;

            case '名词':
                block= new Block();
                blk1 = new Row( root.data[0]);
                block.addRow(blk1)
                id1=this.sentenc.addData(new Row('0'),block);
                return id1;
                break;
            case '多属性名词':
                blk1 = this.genIntCode (root.data[0]);
                blk2 = new Row( root.data[1]);
                id1=this.sentenc.blockAddRow(blk1,blk2);
                return  blk1
                break;
            case '动词A': //
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                block.addRow(new Row( blk1,"1"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '和动词': //
                block= new Block();
                blk1 = this.genIntCode (root.data[0]);
                blk2 = this.genIntCode (root.data[1]);
                block.addRow(new Row( blk1,"1"))
                block.addRow(new Row( blk2,"1"))
                id1=this.sentenc.addData(new Row('1'),block);
                return id1;
                break;
            case '动词': //
                  block= new Block();
                blk1 = new Row( root.data[0]);
                block.addRow(blk1)
                id1=this.sentenc.addData(new Row('0'),block);
                return  id1
                break;

            default:
                break;

        }
    }


    concatenate (blk1, blk2)  {
        blk1.data.push(...blk2.data)
        return blk1;
    }
}
